package com.darly.std.business.store;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.darly.chinese.base.ControllerEnum;
import com.darly.chinese.controller.decompression.ZipDecompressionCommon;
import com.darly.dlcommon.common.bolts.tasks.Task;
import com.darly.dlcommon.common.bolts.tasks.iface.Continuation;
import com.darly.dlcommon.common.dlog.DLog;
import com.darly.dlcommon.framework.ContextController;
import com.darly.rnmodule.component.store.OnStoreDialogListener;
import com.darly.rnmodule.component.store.StoreComponent;
import com.darly.std.BaseApplication;
import com.darly.std.R;
import com.darly.std.obs.NotificationCfg;
import com.darly.std.vm.ActionWrapper;
import com.darly.widget.dialog.SelectItemDialog;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * Description TODO: 设置一个公共能力，弹窗选择窗口。并展示RN布局。
 * Package com.darly.std.business.store
 * Author fronchdarly
 * Date 2021/5/27 10:22 AM
 * Where: 陕西西安
 * How: 特别一般的公司
 */
public class StoreDialogView {

    private StoreDialogView() {
    }

    static class StoreDialogViewHolder {
        static StoreDialogView controller = new StoreDialogView();
    }

    public static StoreDialogView getInstance() {
        return StoreDialogView.StoreDialogViewHolder.controller;
    }



    private Dialog dialog;
    private OnStoreDialogListener listener;

    public void showDialog(final Context context,  OnStoreDialogListener listener){
        this.listener = listener;
        //这里使用RN调用原生弹窗。内部又嵌套RN。必须在UI 线程中进行渲染。否则崩溃。
        Task.call(new Callable() {
            @Override
            public Void call() throws Exception {
                DLog.d("[线程位置：]",Thread.currentThread());
                dialog = new StoreDialog(context);
                dialog.show();
                return null;
            }
        }, Task.UI_THREAD_EXECUTOR);
    }

    public void dismissDialog(String isFinish,String msg){
        if (this.listener!=null){
            if (TextUtils.equals(isFinish,"true")){
                //完成
                this.listener.onConfirm(isFinish,msg);
            }else{
                this.listener.onCancel(isFinish);
            }
        }
        if (dialog!=null && dialog.isShowing()){
            dialog.dismiss();
        }
    }

}
